package com.ruoyi.web.ydz.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.ydz.domain.Reply;
import com.ruoyi.web.ydz.service.IReplyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 帖子回复Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/ydz/reply")
public class ReplyController extends BaseController
{
    @Autowired
    private IReplyService replyService;

    /**
     * 查询帖子回复列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:reply:list')")
    @GetMapping("/list")
    public TableDataInfo list(Reply reply)
    {
        startPage();
        List<Reply> list = replyService.selectReplyList(reply);
        return getDataTable(list);
    }

    /**
     * 导出帖子回复列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:reply:export')")
    @Log(title = "帖子回复", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Reply reply)
    {
        List<Reply> list = replyService.selectReplyList(reply);
        ExcelUtil<Reply> util = new ExcelUtil<Reply>(Reply.class);
        util.exportExcel(response, list, "帖子回复数据");
    }

    /**
     * 获取帖子回复详细信息
     */
    @PreAuthorize("@ss.hasPermi('ydz:reply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(replyService.selectReplyById(id));
    }

    /**
     * 新增帖子回复
     */
    @PreAuthorize("@ss.hasPermi('ydz:reply:add')")
    @Log(title = "帖子回复", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Reply reply, HttpServletRequest request)
    {
        return toAjax(replyService.insertReply(reply,request));
    }

    /**
     * 修改帖子回复
     */
    @PreAuthorize("@ss.hasPermi('ydz:reply:edit')")
    @Log(title = "帖子回复", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Reply reply)
    {
        return toAjax(replyService.updateReply(reply));
    }

    /**
     * 删除帖子回复
     */
    @PreAuthorize("@ss.hasPermi('ydz:reply:remove')")
    @Log(title = "帖子回复", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(replyService.deleteReplyByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('ydz:reply:edit')")
    @Log(title = "修改回复状态", businessType = BusinessType.UPDATE)
    @PutMapping("/editStatus")
    public AjaxResult editStatus(@RequestBody Reply reply)
    {
        return toAjax(replyService.editStatus(reply));
    }


    /*
    * 查询回复所有子集
    * 点击查询全部回复功能
    * */
    @PreAuthorize("@ss.hasPermi('ydz:reply:query')")
    @GetMapping("/getAnyReply")
    public AjaxResult getAnyReply(Long replyId){
        return replyService.getAnyReply(replyId);
    }

    /*
    * 我的评论 功能
    * 查看他人对 我的帖子、评论 进行回复的信息
    * */
    @GetMapping("/getForUsReply")
    public AjaxResult getForUsReply(){
        return replyService.getForUsReply();
    }

    /*
    * 我的点赞功能
    * 查看 其他用户对我的评论 我的帖子点赞情况
    * */
    @GetMapping("/getForUsLike")
    public AjaxResult getForUsLike(){
        return replyService.getForUsLike();
    }

    /*
    * 查看我对 他人帖子及回复 点赞列表
    * */
    @GetMapping("/getToOtherLike")
    public AjaxResult getToOtherLike(){
        return replyService.getToOtherLike();
    }

    /*查看我对 他人帖子及回复 评论列表*/
    @GetMapping("/getToOtherReply")
    public AjaxResult getToOtherReply(){
        return replyService.getToOtherReply();
    }
}
